/*
* @Author: dengjiayao
* @Date:   2017-09-08 09:38:50
* @Last Modified by:   dengjiayao
* @Last Modified time: 2017-09-13 15:13:31
*/
import { showMsg, importNewSharesCustomer } from '../../vuex/action'

export default {
  name: 'customer-import',
  vuex: {
    actions: {
      xShowMsg: showMsg,
      xImport: importNewSharesCustomer
    }
  },
  methods: {
    submit() {
      let el = this.$els.file
      if (el.files.length === 0) {
        return this.xShowMsg({
          type: 'danger',
          content: '请先选择要导入的Excel'
        })
      }
      let file = el.files[0]
      let data = new FormData()
      data.append('excelFile', file)
      this.xImport(data)
        .then(() => {
          el.value = ''
        })
        .catch((res) => {
          return this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    }
  }
}
